<!DOCTYPE html>
<html lang="zh_cn">
<head>
    <meta charset="UTF-8">
    <title>Video Chat</title>

</head>
<body>
    <h1>Realtime communication with WebRTC</h1>

    <video autoplay></video>

</body>

<script type="text/javascript">
    'use strict';
    navigator.getUserMedia = navigator.getUserMedia ||
            navigator.webkitGetUserMedia || navigator.mozGetUserMedia;
    var constraints = {
        audio: true,
        video: true
    };
    var video = document.querySelector('video');

    function successCallback(stream) {
        console.log('successCallback stream : ' , stream);
        console.log('stream.getVideoTracks : ' , stream.getVideoTracks());
//        stream.getVideoTracks()[0].stop();
        window.stream = stream; // stream available to console
        if (window.URL) {
            video.src = window.URL.createObjectURL(stream);
        } else {
            video.src = stream;
        }
    }

    function errorCallback(error) {
        console.log('navigator.getUserMedia error: ', error);
    }

    navigator.getUserMedia(constraints, successCallback, errorCallback);
</script>
</html>